package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {




    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    void insertMeal(Setmeal setmeal);

    /**
     * 套餐分页查询
     * @param setmeal
     * @return
     */
    Page<SetmealVO> getSetmealPage(Setmeal setmeal);



    /**
     * 删除前判断启售状态
     * @param ids
     * @param enable
     * @return
     */
    int countBySetmealStatus(@Param("ids") List<Long> ids, @Param("status") Integer enable);
    /**
     * 套餐批量删除
     * @param ids
     */
    void deleteBySetmealIds(List<Long> ids);
    /**
     * 根据删除中间表是套餐的数据
     * @param setmealDishId
     */
    void deleteBySetmealDishId(@Param("id") Long setmealDishId);

    /**
     * 套餐回显
     * @param id
     * @return
     */
    SetmealVO getBySetmealId(Long id);

    /**
     * 修改套餐
     * @param setmeal
     */
    void updateSetmealWithDish(Setmeal setmeal);

    /**
     * c端条件查询
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);


    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
